import Vue from 'vue'
import Vuex from 'vuex'
import { setStore, getStore, getStoreStr, removeStore } from '../utils/storage'
import { ACCESSTOKEN, USER } from './keys'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    accessToken: getStoreStr(ACCESSTOKEN), //访问凭证
    user: getStore(USER)
  },
  mutations: {
    //设置Phone
    SET_LOGIN(state, obj) {
      state.accessToken = obj.accessToken
      state.user = obj.user
      setStore(ACCESSTOKEN, obj.accessToken)
      setStore(USER, obj.user)
    },
    //删除Phone
    DEL_USER(state) {
      state.accessToken = undefined
      state.user = undefined
      removeStore(ACCESSTOKEN)
      removeStore(USER)
    }
  },
  actions: {
    setLogin({ commit }, obj) {
      commit('SET_LOGIN', obj)
    }
  },
  modules: {}
})
